<?php
class DB {
	private static $link;
	private $queries = array();

	function __construct() {
		if(self::$link == null) {
			self::$link = @mysql_connect(DB_SERVER, DB_USER, DB_PASS) or die($this->error(mysql_error()));
			mysql_select_db(DB, self::$link)or die($this->error(mysql_error()));
		}
	}

	function __destruct() {
		@mysql_close(self::$link);
	}

	public function query($query) {
		array_push($this->queries, $query);
		return mysql_query($query, self::$link);
	}

	private function error($msg) {
		// db.config.php still empty?
		$currConfig = DB_SERVER.DB_USER.DB_PASS.DB;

		if($currConfig == "localhost") {
			echo "<h2>Welcome to the PodcastProject</h2>";
			echo "Please enter you db properties in the config.php";
		} else {
			echo "$msg<br><br>\n\n";
			echo "Please check your config.php";
		}
		
		die();
	}
}

?>
